package datasv.teacherQuery_datasv;

import java.sql.Date;

import data.datafactory.DatabaseOperator;
import po.TeacherPO;
import resultmessage.TeacherQueryRM;

public class AddTeacher {
	public static void main(String[] args) {
		System.out.println(new AddTeacher().addTeacher(new TeacherPO("001132014", "testTeacher", "001", 2013, new Date(1981,03,23))));
	}
	public TeacherQueryRM addTeacher(TeacherPO po){
		return addInSql(po);
	}

	private TeacherQueryRM addInSql(TeacherPO po) {
		// TODO Auto-generated method stub
		DatabaseOperator op=new DatabaseOperator("college"+po.getCollegeID());
		String listName="teacher_list";
		if(!op.ifDatabaseExist()||op.ifIDExist(listName, po.getTeacherID())){
			return TeacherQueryRM.TEACHERID_EXIST;
		}
		String[][] info={{"id",po.getTeacherID()},{"name",po.getName()},{"birthday",Integer.toString(po.getBirthday().getYear())+"/"+Integer.toString(po.getBirthday().getMonth())+"/"+Integer.toString(po.getBirthday().getDate())},{"workStartYear",Integer.toString(po.getWorkStartYear())},{"collegeID",po.getCollegeID()}};
		if(!op.addOneRow(info, listName)){
			return TeacherQueryRM.TEACHERID_EXIST;
		}
		
		return TeacherQueryRM.SUCCESS;
	}
}
